package com.itheima.controller;

import com.github.pagehelper.Page;
import com.itheima.entity.PageResult;
import com.itheima.pojo.Comment;
import com.itheima.service.CommentService;
import com.itheima.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @PostMapping("/getList")
    public Result getList(@RequestBody Map<String,Object> commentVO){
        PageResult<Comment> commentPage = commentService.findAll(commentVO);
        return new Result("success",commentPage);
    }
    @PostMapping("/edit")
    public Result edit(@RequestBody Map<String,Object> commentVO){
        commentService.edit(commentVO);
        return new Result("success","操作成功");
    }

    @PostMapping("/delete")
    public Result delete(@RequestBody Map<String,Object> commentVO){
        commentService.delete(commentVO);
        return new Result("success","操作成功");
    }

    @PostMapping("/add")
    public Result add(@RequestBody Map<String,Object> commentVO){
        commentService.add(commentVO);
        return new Result("success","操作成功");
    }

    @PostMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Map<String,Object>> commentVoList){
        commentService.deleteBatch(commentVoList);
        return new Result("success","操作成功");
    }
}
